home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997 August / Macworld (1997-08).dmg / Serious Demos / Crimson Demo / Crimson Demos / Customer File / CustFrmCode < prev    next >
Text File  |  1997-06-17  |  3KB  |  138 lines

  1. Procedure NextBtn.Click()
  2.         Inc CurrentRecord
  3.         If Populate_CustForm(CurrentRecord)=False
  4.                 Dec CurrentRecord
  5.         Endif
  6. Return
  7.  
  8. Procedure PrevBtn.Click()
  9.         Dec CurrentRecord
  10.         If CurrentRecord>0
  11.                 If Populate_CustForm(CurrentRecord)=False
  12.                         Inc CurrentRecord
  13.                 Endif
  14.         Endif
  15. Return
  16.  
  17. Procedure AddBtn.Click()
  18.         Do Case
  19.                 Case Mode={Q}
  20.                         CustNo.Value=Str(NextFreeRec)
  21.                         CustName.Value=""
  22.                         CustAddr.Value=""
  23.                         CustPhone.Value=""
  24.                         CustFax.Value=""
  25.                         CustEmail.Value=""
  26.                         CustLocn.Value=1
  27.                         NextBtn.Enabled=False
  28.                         PrevBtn.Enabled=False
  29.                         AddBtn.Caption="Save"
  30.                         UpdateBtn.Caption="Cancel"
  31.                         LocateBtn.Enabled=False
  32.                         QuitBtn.Enabled=False
  33.                         Mode={A}
  34.                         Break
  35.                 Case Mode={A}
  36.                         Do Update_Record(NextFreeRec)
  37.                         CurrentRecord=NextFreeRec
  38.                         LocateForm.LBox.InsertRow(CurrentRecord,CustName.Value)
  39.                         Inc NextFreeRec
  40.                         NextBtn.Enabled=True
  41.                         PrevBtn.Enabled=True
  42.                         AddBtn.Caption="Add"
  43.                         UpdateBtn.Caption="Update"
  44.                         LocateBtn.Enabled=True
  45.                         QuitBtn.Enabled=True
  46.                         Mode={Q}
  47.                         Break
  48.                 Case Mode={U}
  49.                         Do Update_Record(CurrentRecord)
  50.                         LocateForm.LBox.SetRow(CurrentRecord,CustName.Value)
  51.                         NextBtn.Enabled=True
  52.                         PrevBtn.Enabled=True
  53.                         AddBtn.Caption="Add"
  54.                         UpdateBtn.Caption="Update"
  55.                         LocateBtn.Enabled=True
  56.                         QuitBtn.Enabled=True
  57.                         Mode={Q}
  58.         Endcase
  59. Return
  60.  
  61. Procedure UpdateBtn.Click()
  62.         If Mode={Q}
  63.                 NextBtn.Enabled=False
  64.                 PrevBtn.Enabled=False
  65.                 AddBtn.Caption="Save"
  66.                 UpdateBtn.Caption="Cancel"
  67.                 LocateBtn.Enabled=False
  68.                 QuitBtn.Enabled=False
  69.                 Mode={U}
  70.         Else
  71.                 NextBtn.Enabled=True
  72.                 PrevBtn.Enabled=True
  73.                 AddBtn.Caption="Add"
  74.                 UpdateBtn.Caption="Update"
  75.                 LocateBtn.Enabled=True
  76.                 QuitBtn.Enabled=True
  77.                 Mode={Q}
  78.         Endif
  79. Return                
  80.  
  81. Procedure LocateBtn.Click()
  82.         LocateForm.ShowWindow
  83. Return
  84.  
  85. Procedure QuitBtn.Click()
  86.         Close #1
  87.         End
  88. Return
  89.         
  90. Function Populate_CustForm(RecNo) Returning Integer Public 
  91. Parameter RecNo As Integer
  92. Local CustStruct As Structure
  93.         Local Cust_no As Integer
  94.         Local Cust_name As String [30]
  95.         Local Cust_addr As String [255]
  96.         Local Cust_phone As String [16]
  97.         Local Cust_fax As String [16]
  98.         Local Cust_email As String [30]
  99.         Local Cust_location As Integer
  100. Endstruct
  101.  
  102.         Get #1,RecNo,CustStruct
  103.         If ERR
  104.                 Return False
  105.         Endif
  106.  
  107.         CustNo.Value=Str(Cust_no)
  108.         CustName.Value=Cust_name
  109.         CustAddr.Value=Cust_addr
  110.         CustPhone.Value=Cust_phone
  111.         CustFax.Value=Cust_fax
  112.         CustEmail.Value=Cust_email
  113.         CustLocn.Value=Cust_Location
  114. Return True
  115.  
  116. Procedure Update_Record(RecNo)
  117. Parameter RecNo As Integer
  118.  
  119. Local CustStruct As Structure
  120.         Local Cust_no As Integer
  121.         Local Cust_name As String [30]
  122.         Local Cust_addr As String [255]
  123.         Local Cust_phone As String [16]
  124.         Local Cust_fax As String [16]
  125.         Local Cust_email As String [30]
  126.         Local Cust_location As Integer
  127. Endstruct
  128.  
  129.         Cust_no=RecNo
  130.         Cust_name=CustName.Value
  131.         Cust_addr=CustAddr.Value
  132.         Cust_phone=CustPhone.Value
  133.         Cust_fax=CustFax.Value
  134.         Cust_email=CustEmail.Value
  135.         Cust_Location=CustLocn.Value
  136.         Put #1,RecNo,CustStruct
  137. Return
  138.